package mapper

import (
	"gorm.io/gorm"
	"ylb/config"
	"ylb/entity"
	"ylb/tool"
)

type NoteMapper struct {
	DB *gorm.DB
}

func NewNoteMapper() NoteMapper {
	mapper := NoteMapper{}
	mapper.DB = tool.GetGormConnection(config.GetDBUrlConfig())
	return mapper
}
func (note NoteMapper) SelectNoteByUserId(userId uint) entity.Note {
	e := entity.Note{}
	note.DB.Where("user_id =?", userId).Find(&e)
	return e
}
func (note NoteMapper) Update(newNote entity.Note) int64 {

	return note.DB.Where("user_id=?", newNote.UserId).Updates(newNote).RowsAffected
}
func (note NoteMapper) InsertOne(n entity.Note) int64 {
	e := entity.Note{UserId: n.UserId}
	return note.DB.Create(&e).RowsAffected
}
